#define  _CRT_SECURE_NO_WARNINGS
class Solution {
public:
    int pivotIndex(vector<int>& nums) {
        vector<int> f(nums.size(), 0), g(nums.size(), 0);
        for (int i = 1; i < nums.size(); i++) f[i] = f[i - 1] + nums[i - 1];
        for (int i = nums.size() - 2; i >= 0; i--)g[i] = g[i + 1] + nums[i + 1];
        for (int i = 0; i < nums.size(); i++) if (f[i] == g[i]) return i;
        return -1;
    }
};